<?php
	require_once "includes/class/member_management.class.php";
	require_once('AmazonAPI/.config.inc.php');
	require_once('AmazonAPI/CBUI/CBUIRecipientTokenPipeline.php');
	
	if($_SESSION['user_id_sess']=="") {
		echo "<script type='text/javascript'> window.location='index.php?signin&url=profile'; </script>";
	}
	if(isset($_REQUEST['signature']) && !empty($_REQUEST['signature'])) {
			$signature = $_REQUEST['signature'];
			$refundTokenID = $_REQUEST['refundTokenID'];
			$signatureVersion = $_REQUEST['signatureVersion'];
			$signatureMethod = $_REQUEST['signatureMethod'];
			$certificateUrl = $_REQUEST['certificateUrl'];
			$tokenID = $_REQUEST['tokenID'];
			$callerReference = $_REQUEST['callerReference'];
			$sqlUpdUsr = "UPDATE tbl_users SET comm_signature='".$signature."',
						comm_refundTokenID='".$refundTokenID."',
						comm_signatureVersion='".$signatureVersion."',
						comm_signatureMethod='".$signatureMethod."',					
						comm_certificateUrl='".$certificateUrl."',
						comm_tokenID='".$tokenID."',
						comm_callerReference='".$callerReference."' WHERE user_id='$userId'";
			$rstUpdUsr = mysql_query($sqlUpdUsr) or die(mysql_error());
			if($rstUpdUsr) { 
				$msg = "Your tokenID is successfully set.";
			}else{
				$msg = "Your tokenID is not set please try again!";
			}
		}	
	if($_REQUEST['comm_token_id']!=1)
	{
		$userId = $_SESSION['user_id_sess'];	
		$usrObj = new member_management;
		$rand = rand(100000, 10000000);		
	
		$pipeline = new Amazon_FPS_CBUIRecipientTokenPipeline(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY);
			
			$pipeline->setMandatoryParameters("swapen".rand(),  
					H_ROOT."index.php?comm_token_id=1", "0", "0.0", "True");
					
			$pipeline->addParameter("paymentMethod", "CC");
			$re_URL = $pipeline->getUrl();
			header("location:".$re_URL);
	}
	else
	{
		header("location:index.php?profile=1");
		//echo 'hi';
	}
	//print_r($userInfo);	
?>
